package com.audaque.springboot.foshanupload.web.webdemo.controller;

import cn.hutool.core.net.url.UrlBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

/**
 * @author wangyan01
 */

@Slf4j
@RestController
@RequestMapping("url")
public class UrlController {

    @GetMapping("urlBuilder1")
    public String urlBuilder1() throws Exception {
        log.debug("2");
        //不编码
        return UrlBuilder.create().setScheme("http").setHost("localhost").addPath("/#/ieg_support/engineering/detail/658cdd159795aa1fc2da0e0c").setCharset(null).build();
    }

    @GetMapping("urlBuilder2")
    public String urlBuilder2() throws Exception {
        //编码
        return UrlBuilder.create().setScheme("http").setHost("localhost").addPath("/#/ieg_support/engineering/detail/658cdd159795aa1fc2da0e0c").build()+666;
    }

    @GetMapping("urlEncoder")
    public String urlEncoder() throws Exception {
        // 拼凑get请求的URL字串，使用URLEncoder.encode对特殊和不可见字符进行编码
       return   "http://www.baidu.com" + "?username="+ URLEncoder.encode("飞猪 man", "utf-8");
    }




}
